package com.entrogy.dao;

import com.alibaba.fastjson.JSONObject;
import com.entrogy.bean.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName DormMapper
 * @Description
 * @Author luoxingjiang
 * @Date 2019/7/9 0009 下午 2:58
 * @Version 1.0
 **/
@Repository
public interface DormMapper {

    /**
     * 查询宿舍列表
     * @param schoolCode
     * @param uid 生活老师id
     * @param dormName
     * @return
     */
    List<DormEntity> listDorm(@Param(value = "schoolCode") Integer schoolCode, @Param(value = "uid") String uid, @Param(value = "dormName") String dormName);

    /**
     * 新增宿舍
     * @param dorm
     * @return
     */
    int insertDorm(DormEntity dorm);

    /**
     * 更改宿舍名
     * @param dorm
     * @return
     */
    int updateDorm(DormEntity dorm);

    /**
     * 删除宿舍
     * @param dormId
     * @return
     */
    int deleteDorm(Integer dormId);

    /**
     * 删除楼层表记录
     * @param dormId
     * @return
     */
    int deleteFloorByDormId(Integer dormId);

    /**
     * 删除所有宿舍闸机信息
     * @param dormId
     * @return
     */
    int deleteDormDevice(Integer dormId);

    /**
     * 通过班级id批量更新学生入住的寝室
     * @param dormId
     * @param classId
     * @param schoolCode
     * @return
     */
    int updateStudentDormByClassId(@Param(value = "dormId") Integer dormId, @Param(value = "classId")Integer classId, @Param(value = "schoolCode")Integer schoolCode);

    /**
     * 批量将学生从宿舍内删除
     * @param dormId
     * @param studentIds
     * @return
     */
    int deleteStudentsFromDormId(@Param(value = "dormId") Integer dormId, @Param(value = "studentIds") List<Integer> studentIds);

    /**
     * 为宿舍分配一台闸机
     * @param params
     * @return
     */
    int assignDevices(Map<String, Object> params);

    /**
     * 指定删除宿舍闸机
     * @param dormId
     * @param deviceIds
     * @return
     */
    int deleteDeviceByDeviceIds(@Param(value = "dormId") Integer dormId, @Param(value = "deviceIds") List<Integer> deviceIds);

    /**
     * 为宿舍分配楼层
     * @param dormId
     * @param order
     * @return
     */
    int insertDormFloor(@Param(value = "dormId") int dormId, @Param(value = "order") int order);

    /**
     * 查找该校的所有生活老师
     * @param schoolCode
     * @return
     */
    List<LifeTeacherEntity> getListLifeTeacher(Integer schoolCode);

    /**
     * 更新楼层的生活老师
     * @param lifeTeacherId
     * @param id
     * @return
     */
    int updateFloorLifeTeacher(@Param(value = "lifeTeacherId") String lifeTeacherId, @Param(value = "id") Integer id);

    /**
     * 查询年级的归寝时间列表
     * @param schoolCode
     * @return
     */
    List<GradeEntity> listGradeBackTime(@Param(value = "schoolCode") Integer schoolCode, @Param(value = "gradeId") Integer gradeId);

    /**
     * 批量设置年级的归寝时间
     * @param updateBackTimeFrameList
     * @return
     */
    int updateGradeBackTime(@Param(value = "backTimeFrameList") List<UpdateBackTimeFrameEntity> updateBackTimeFrameList);

    /**
     * 创建年级的归寝时间
     * @param backTimeFrame
     * @return
     */
    int insertGradeBackTimeFrame(UpdateBackTimeFrameEntity backTimeFrame);

    /**
     * 根据实义德的id查询学生的归寝时间
     * @param id
     * @return
     */
    Date getStudentBackTimeByThdid(int id,int schoolCode);

    /**
     * 统计在指定的归寝时间内没有通行记录的学生
     * @param tableName
     * @param gradeId
     * @param dormId
     * @return
     */
    List<Integer> listLateStudentByNoRecord(@Param(value = "tableName") String tableName, @Param(value = "gradeId") Integer gradeId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "dormId") Integer dormId);

    /**
     * 返回未归寝学生信息
     * @param lateStudentList
     * @return
     */
    int insertLateStudent(@Param(value = "lateStudentList") List<AttendanceExceptionStudentEntity> lateStudentList);

    /**
     * 通行记录为为双数的迟到学生
     * @param schoolCode
     * @param userId
     * @param gradeId
     * @param dormId
     * @return
     */
    List<AttendanceExceptionStudentEntity> listLateStudentByHasTwoRecord(@Param(value = "tableName") String tableName, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "userId") String userId, @Param(value = "gradeId") Integer gradeId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "dormId") Integer dormId);

    /**
     * 生活老师查看迟到学生列表
     * @param dormId
     * @return
     */
    List<AttendanceExceptionStudentEntity> lifeTeacherDormAttendance(@Param(value = "dormId") Integer dormId, @Param(value = "time") Date time);

    /**
     * 教师查看迟到学生列表
     * @param classId
     * @return
     */
    List<AttendanceExceptionStudentEntity> teacherDormAttendance(@Param(value = "classId")Integer classId, @Param(value = "time") Date time);

    /**
     * 查询生活老师所在宿舍某个年级的归寝时间
     * @param userId
     * @param gradeId
     * @return
     */
    Date getBackTimeByLifeTeacherId(@Param(value = "userId") String userId, @Param(value = "gradeId") Integer gradeId);


    /**
     * 根据生活老师id将所在宿舍所住年级查询出来
     * @param uid
     * @return
     */
    List<GradeEntity> listDormGradeByLifeTeacher(String uid);

    /**
     * 将有通行记录但是没有在归寝时段内通行的学生记为未归寝
     * @param tableName
     * @param schoolCode
     * @param userId
     * @param gradeId
     * @return
     */
    List<AttendanceExceptionStudentEntity> listLateStudentByHasRecord(@Param(value = "tableName") String tableName, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "userId") String userId, @Param(value = "gradeId") Integer gradeId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime);

    /**
     * 查询某一个年级的归寝时段
     * @param schoolCode
     * @param gradeId
     * @return
     */
    BackTimeFrameEntity getGradeBackTimeFrame(@Param(value = "schoolCode") Integer schoolCode, @Param(value = "gradeId") Integer gradeId);

    /**
     * 查询生活老师所在宿舍
     * @param userId
     * @return
     */
    List<Integer> getDormIdByTeacherId(String userId);

    /**
     * 根据dormId查询查询没有在这些寝室打卡的学生id
     * @param dormIds
     * @return
     */
//    List<Integer> listNoDormPassRecord(@Param(value = "tableName") String tableName, @Param(value = "dormIds") List<Integer> dormIds,  @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime);

    /**
     * 查询未归寝学生的信息
     * @param studentId
     * @param tableName
     * @return
     */
    AttendanceExceptionStudentEntity getStudentLateInfo(@Param(value = "studentId")Integer studentId, @Param(value = "tableName")String tableName);

    /**
     * 查询年纪点名表，看当天该年级是否已经点过名了
     * @param gradeId
     * @param schoolCode
     * @param checkTime
     * @param dormId
     * @return
     */
    Integer countGradeCheckedRecord(@Param(value = "gradeId") Integer gradeId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "checkTime") String checkTime, @Param(value = "dormId") Integer dormId);


    /**
     * 向点名记录表内插入一条记录
     * @param gradeId
     * @param schoolCode
     * @param dormId
     * @param checkGradeTime
     * @return
     */
    Integer addGradeCheckedRecord(@Param(value = "gradeId") Integer gradeId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "dormId") Integer dormId, @Param(value = "checkTime") String checkGradeTime);

    /**
     * 删除该年级的归寝时间数据
     * @param updateBackTime
     * @return
     */
    Integer deleteGradeBackTime(UpdateBackTimeFrameEntity updateBackTime);

    /**
     * 插入年级的归寝时间数据
     * @param updateBackTimeFrameList
     * @return
     */
    int insertGradeBackTime(@Param(value = "updateBackTimeFrameList") List<UpdateBackTimeFrameEntity> updateBackTimeFrameList);

    /**
     * 更新学生所住楼层及宿舍信息
     * @param floorId
     * @param studentIdList
     * @param dormId
     * @return
     */
    Integer updateStudentFloor(@Param(value = "floorId") Integer floorId, @Param(value = "studentIdList") List<Integer> studentIdList, @Param(value = "dormId") Integer dormId);

    /**
     * 将某些学生从宿舍的楼层移除
     *
     * @param id
     * @param gradeId
     * @param floorId
     * @return
     */
    Integer deleteStudentFromFloor(@Param(value = "floorId") Integer floorId, @Param(value = "gradeId") Integer gradeId, @Param(value = "classId") Integer classId);

    /**
     * 根据生活老师id查询楼层id
     * @param userId
     * @return
     */
    List<Integer> listFloorId(String userId);

    /**
     * 根据楼层id查询宿舍id
     * @param floorId
     * @return
     */
    Integer getDormIdByFloorId(Integer floorId);

    /**
     * 更新学生的宿舍id
     * @param dormId
     * @param studentIdList
     * @return
     */
    Integer updateStudentDorm(@Param(value = "dormId") Integer dormId, @Param(value = "studentIdList") List<Integer> studentIdList);

    /**
     * 查询该楼层的所有学生列表
     * @param floorId
     * @param dormId
     * @return
     */
    List<JSONObject> listFloorStudent(@Param(value = "floorId") Integer floorId, @Param(value = "dormId") Integer dormId);

    /**
     * 查询该楼层的所有学生总数
     * @param floorId
     * @param dormId
     * @return
     */
    Integer countFloorStudent(@Param(value = "floorId") Integer floorId, @Param(value = "dormId") Integer dormId);

    /**
     * 查询该宿舍的所有设备
     * @param dormId
     * @return
     */
    List<String> listDormDevice(Integer dormId);

    /**
     * 查询该校所有的宿舍名
     * @param schoolCode
     * @return
     */
    List<String> listDormName(Integer schoolCode);

    /**
     * 根据寝室id和楼层数查询楼层id
     * @param dormId
     * @param order
     * @return
     */
    Integer getFloorId(@Param("dormId") Integer dormId, @Param("order") Integer order);

    /**
     * 分配寝室大门的设备
     * @param dormDoorDevice
     * @return
     */
    int insertDormDoorDevice(DormDoorDeviceEntity dormDoorDevice);

    /**
     * 更新寝室大门的设备信息
     * @param userId
     * @param dormDoorDeviceId
     * @param deleteStatus
     * @return
     */
    int updateDormDoorDevice(@Param("userId") String userId, @Param("dormDoorDeviceId") Integer dormDoorDeviceId, @Param("deleteStatus") Integer deleteStatus);

    /**
     * 查询寝室的大门设备
     * @param dormId
     * @param inOrOut
     * @return
     */
    List<DormDoorDeviceEntity> listDormDoorDevice(@Param("dormId") Integer dormId, @Param("inOrOut") String inOrOut);
}
